#DROP table "url";
#DROP table "urlinfo";
#DROP table "dict";
#DROP SEQUENCE next_url_id;


CREATE SEQUENCE next_url_id;

CREATE TABLE "url" (
	"rec_id"          int4 DEFAULT nextval('next_url_id') PRIMARY KEY,
	"status"          int4 NOT NULL DEFAULT 0,
	"url"             text NOT NULL,
	"content_type"    text NOT NULL DEFAULT '',
	"docsize"         int4 NOT NULL DEFAULT 0,
	"next_index_time" int4 NOT NULL,
	"last_mod_time"   int4,
	"referrer"        int4 NOT NULL DEFAULT 0,
	"tag"             text NOT NULL DEFAULT '',
	"hops"            int4 NOT NULL DEFAULT 0,
	"category"        text NOT NULL DEFAULT '',
	"crc32"           int4 NOT NULL DEFAULT 0,
        "lang"            text NOT NULL DEFAULT '',
        "charset"         text NOT NULL DEFAULT '',
	"seed"            int NOT NULL DEFAULT 0
);

CREATE TABLE "urlinfo" (
       url_id int4 NOT NULL,
       sname  text NOT NULL,
       sval   text NOT NULL
);

CREATE INDEX urlinfo_id ON urlinfo (url_id);

CREATE TABLE "dict" (
	"url_id" int4 NOT NULL,
	"word"   text NOT NULL,
	"intag"  int4 NOT NULL
);

CREATE  INDEX "dict_word"  on "dict" using btree ( "word"   );
CREATE  INDEX "dict_url"   on "dict" using btree ( "url_id" );

CREATE  UNIQUE INDEX "url_url" on "url" using btree ( "url" "varchar_ops" );
CREATE  INDEX "url_crc" on "url" using btree ( "crc32" );
CREATE  INDEX "url_seed" on "url" USING btree ( "seed" );
CREATE  INDEX "url_referrer" on "url" USING btree ( "referrer" );

CREATE INDEX url_crc32_status_docsize ON url (crc32,status,docsize);
CREATE INDEX dict_word_url_id ON dict (word, url_id);

